<?php

namespace App\Console\Commands;

use App\Http\Controllers\HouseController;
use App\Models\RentAndPurchase;
use App\Services\HouseServices;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class RentAndPurchaseCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'RentAndPurchase';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $data = RentAndPurchase::whereDate('house_end_time','<',date("Y-m-d",time()))->get(['id']);
        foreach ($data as $v){
            RentAndPurchase::where('id',$v['id'])->delete();
        }
        $controller = (new HouseServices())->redisDel($data);
        if(empty($controller)){
            Log::info('删除成功');
        }

    }
}
